﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;
using RimWorld;

namespace Miao.Stand
{
    /// <summary>
    /// 替身保护替身使者
    /// </summary>
    public class HediffCompProperties_StandCoverMaster : HediffCompProperties
    {
        //public float cover = 0.4f;//格挡触发概率
        public int coverTick = 200;

        public HediffCompProperties_StandCoverMaster()
        {
            compClass = typeof(HediffComp_StandMasterCover);
        }
    }

    public class HediffComp_StandMasterCover : HediffComp
    {
        new public StandMasterHediff parent
        {
            get
            {
                return base.parent as StandMasterHediff;
            }
        }
        public StandPawn stand
        {
            get
            {
                return parent.stand;
            }
        }


        public HediffCompProperties_StandCoverMaster Props => (HediffCompProperties_StandCoverMaster)props;



 
        public override void Notify_PawnPostApplyDamage(DamageInfo dinfo, float totalDamageDealt)
        {
            //不太可能调反射动态赋Comps，关联的东西太多了。
            if (stand.Spawned)
            {
                if (stand.CurJob.def == StandJobDefOf.StandGhostFollow)
                {
                    //近战攻击几下
                    if (parent.pawn.mindState.meleeThreat != null)
                    {
                        Job meleeThreatjob = JobMaker.MakeJob(JobDefOf.AttackMelee, Pawn.mindState.meleeThreat);
                        meleeThreatjob.maxNumMeleeAttacks = 1;
                        meleeThreatjob.expiryInterval = 300;
                        meleeThreatjob.reactingToMeleeThreat = true;//对威胁做出反应
                        stand.jobs.TryTakeOrderedJob(meleeThreatjob, JobTag.Misc);
                    }
                    else
                    {
                        Job coverMaster = JobMaker.MakeJob(StandJobDefOf.CoverMaster);
                        stand.jobs.TryTakeOrderedJob(coverMaster, JobTag.Misc);
                        coverMaster.expiryInterval = Props.coverTick;
                    }
                }
                else if (stand.CurJob.def == StandJobDefOf.CoverMaster)
                {
                    stand.CurJob.startTick = 0;
                }
            }

            base.Notify_PawnPostApplyDamage(dinfo, totalDamageDealt);


        }
    }
}
